import App from './App'
import music from '@/utils.js'
// 导入vuex实例
import store from './vuex/store'
Vue.prototype.$music = music
// 导入axios网络请求
import {
  $http
} from '@escook/request-miniprogram'

// 注册
uni.$http = $http
// 配置根基准地址
$http.baseUrl = 'http://localhost:3000'
// // 请求拦截
// $http.beforeRequest = function(options) {
//   uni.showLoading({
//     title: '加载中'
//   })
// }
// // 响应拦截
// $http.afterRequest = function() {
//   uni.hideLoading()
// }
// 封装消息弹框
// 封装消息弹框

// 请求头添加cookie
$http.beforeRequest = function(options) {
  const userinfo = store.state.musicMyPage.userInfo
  // console.log(userinfo.cookies)
  if (userinfo.cookies) {
    options.header = {
      cookie: userinfo.cookies.find(item => item.indexOf('MUSIC_U') !== -1)
    }
  }
}
uni.$showMsg = function(title = '数据加载失败！', duration = 1500) {
  uni.showToast({
    title,
    duration,
    icon: 'none',
  })
}
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
  store,
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
  createSSRApp
} from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif
